package com.cy.myblog.service.impl;

import com.cy.myblog.dao.BaseDaoI;
import com.cy.myblog.model.Tmenu;
import com.cy.myblog.service.RepairServiceI;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2015/7/14.
 */
@Service("repairService")
public class RepairServiceImpl implements RepairServiceI{

    private BaseDaoI<Tmenu> menuDao;

    @Resource(name = "baseDao")
    public void setMenuDao(BaseDaoI<Tmenu> menuDao) {
        this.menuDao = menuDao;
    }

    @Override
    synchronized public void repair() {
        repairMenu();
    }

    public void repairMenu() {
        Tmenu root = new Tmenu();
        root.setId("0");
        root.setName("首页");
        root.setUrl("");
        menuDao.saveOrUpdate(root);

        Tmenu yhgl = new Tmenu();
        yhgl.setId("1");
        yhgl.setName("用户管理");
        yhgl.setTmenu(root);
        yhgl.setUrl("");
        menuDao.saveOrUpdate(yhgl);

        Tmenu wzgl = new Tmenu();
        wzgl.setId("2");
        wzgl.setName("文章管理");
        wzgl.setTmenu(root);
        wzgl.setUrl("");
        menuDao.saveOrUpdate(wzgl);

        Tmenu fbwz = new Tmenu();
        fbwz.setId("21");
        fbwz.setName("发表文章");
        fbwz.setTmenu(wzgl);
        fbwz.setUrl("");
        fbwz.setClick("");
        fbwz.setParameter("/jsp/backend/article/edit_article.jsp");
        menuDao.saveOrUpdate(fbwz);

        Tmenu flgl = new Tmenu();
        flgl.setId("22");
        flgl.setName("分类管理");
        flgl.setTmenu(wzgl);
        flgl.setUrl("");
        flgl.setClick("");
        flgl.setParameter("/jsp/backend/article/classify.jsp");
        menuDao.saveOrUpdate(flgl);
    }
}
